package com.ssyt.yt1.day9.abstractdemo;

/**
 * 创建一个Vehicle类并将它声明为抽象类。在Vehicle类中声明一个NoOfWheels方法，使它返回一个字符串值。
 * 创建两个类Car和Motorbike从Vehicle类继承
 * ，并在这两个类中实现NoOfWheels方法。在Car类中，应当显示“四轮车”信息；而在Motorbike类中
 * ，应当显示“双轮车”信息。创建另一个带main方法的类，在该类中创建Car和Motorbike的实例，并在控制台中显示消息。
 * 
 * @author Administrator
 *
 */
abstract class Vehicle {

	private String name;
	private int noOfWheels;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setNoOfWheels(int noOfWheels) {
		this.noOfWheels = noOfWheels;
	}

	public int getNoOfWheels() {
		return noOfWheels;
	}

	/**
	 * 此方法子类必须重写！
	 * 
	 * @return
	 */
	public abstract int fetchNoOfWheels();

	/**
	 * 此方法子类可选重写！
	 */
	public void a() {

	}
}

/**
 * 四轮车
 * 
 * @author Administrator
 *
 */
class Car extends Vehicle {

	public Car() {
		super();
	}

	public Car(String name, int noOfWheels) {
		super();
		this.setName(name);
		this.setNoOfWheels(noOfWheels);
	}

	@Override
	public int fetchNoOfWheels() {
		return getNoOfWheels();
	}

	@Override
	public String toString() {
		return "Car [getName()=" + getName() + ", getNoOfWheels()="
				+ getNoOfWheels() + "]";
	}

}

/**
 * 摩托车
 * 
 * @author Administrator
 *
 */
class Motorbike extends Vehicle {

	public Motorbike() {
		super();
	}

	public Motorbike(String name, int noOfWheels) {
		super();
		this.setName(name);
		this.setNoOfWheels(noOfWheels);
	}

	@Override
	public int fetchNoOfWheels() {
		return getNoOfWheels();
	}

	@Override
	public String toString() {
		return "Motorbike [getName()=" + getName() + ", getNoOfWheels()="
				+ getNoOfWheels() + "]";
	}

}

public class VehicleDemo {

	public static void main(String[] args) {
		System.out.println(new Car("Benz", 4));
	}
}
